package com.beauty.product.dto;

import com.beauty.product.entity.ProductAttribute;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProductAttributeDto {
    
    private Long id;
    
    private String productId;
    
    @NotBlank(message = "属性名称不能为空")
    private String name;
    
    @NotBlank(message = "属性值不能为空")
    private String value;
    
    private Integer sort = 0;
    
    private Boolean isSearchable = false;
    
    private Boolean isVisible = true;
    
    public static ProductAttributeDto fromEntity(ProductAttribute attribute) {
        ProductAttributeDto dto = new ProductAttributeDto();
        dto.setId(attribute.getId());
        dto.setProductId(attribute.getProductId());
        dto.setName(attribute.getName());
        dto.setValue(attribute.getValue());
        dto.setSort(attribute.getSort());
        dto.setIsSearchable(attribute.getIsSearchable());
        dto.setIsVisible(attribute.getIsVisible());
        return dto;
    }
    
    public ProductAttribute toEntity() {
        ProductAttribute attribute = new ProductAttribute();
        attribute.setId(this.id);
        attribute.setProductId(this.productId);
        attribute.setName(this.name);
        attribute.setValue(this.value);
        attribute.setSort(this.sort);
        attribute.setIsSearchable(this.isSearchable);
        attribute.setIsVisible(this.isVisible);
        return attribute;
    }
} 